<?php
namespace app\servergoods\validate;
use \app\manage\validate\BaseValidate;

class Goods extends BaseValidate
{
    //添加和编辑的时候的验证规则
	protected $rule =   [
        'id'  => ['integer','gt'=>0],
        'app_id'  => ['integer','gt'=>0],
        'user_id'  => ['integer','gt'=>0],
        'cate_id'  => ['integer','gt'=>0],
        'title'    => ['length'=>'2,25'],
        'product_code' => ['min'=>'10'],
    	'imgs_urls'=> ['min'=>'1'],
        'imgs_ids' => ['min'=>'1'],
        'price'=> ['integer','gt'=>0],
        'currency'=> ['number','gt'=>0],
        'user_name'=> ['min'=>'2'],
        'goods_belonger_name'=> ['min'=>'2'],
        'user_phone'=> ['regex'=>'/^1[3|4|5|7|8]\d{9}$/'],
        'goods_attrs'=> ['array'],
        'pattern'=> ['array','min'=>1],
        'standard'=>['array','min'=>1],
        'number'=> ['integer','gt'=>0],
        'origin_number'=> ['integer','gt'=>0],
        'pay_method'=> ['in'=>'0,1,2'],
        'delivery_type'=> ['in'=>'1,2'],
        'province'=> ['integer','egt'=>0],
        'city'=> ['integer','egt'=>0],
        'county'=> ['integer','egt'=>0],
        'order'=> ['integer','egt'=>0],
        'operate_uid'=> ['integer','gt'=>0],
        'page'=>['integer','gt'=>0],
        'listRows'=>['integer','gt'=>0,'elt'=>50],
        //'recommend' => ['regex' => '^(\w)+(,\w+)*'],  //  brand,person
        'recommend' => ['min'=>2],  //  brand,person
        'price_start' => ['integer','egt'=>0],
        'price_end' => ['integer','egt'=>0],
        'symbol' => ['in'=>'elt,between,egt'],
        'pick_up_time' => ['integer','gt'=>0],     
        'start_delivery_time' => ['integer','egt'=>0],     
        'end_delivery_time' => ['integer','egt'=>0],     
        'limit' => ['integer','gt'=>0],  
        'goods_ids' => ['regex' => '^\d+(,\d+)*$'],
        'is_sell' => ['in'=>'0,1'], 
        /*账单验证*/
        'create_user_info' => ['array'],
        'goods_id'  => ['integer','gt'=>0],
        'order_number'  => ['integer','gt'=>0],
        'total_price'  => ['integer'],
        'remark'  => ['min'=>2],
        'time' => ['in'=>'threeMonthAgo,threeMonth'],
        'multiple' => ['number', 'gt'=>0],
        'currency_multiple' => ['number', 'gt'=>0],
    ];

    protected $message  =   [
        'cate_id' => '请选择分类',
        'title'   => '藏品名称在2-25个字符之间',
        'imgs_urls' => '图片地址不可为空',
        'imgs_ids'  => '图片id不能为空',
        'desc'  => '商品描述至少2个字符',
        'price'  => '价格为大于0的整数',
        'user_name'  => '请填写联系人姓名',
        'user_phone'  => '请正确填写联系人手机号码',
        'goods_attrs'  => '商品属性未填写完整，请完整填写信息',
        'pattern'  => '请选择断代/款识',
        'standard'  => '请填写规格',
        'number'  => '数量为大于0的整数',
        'origin_number'  => '原始数量为大于0的整数',
        'pay_method'  => '支付方式错误',
        'delivery_type'  => '交割方式错误',
        'province'  => '请重新选择省份',
        'city'  => '请重新选择城市',
        'county'  => '请重新选择地区',
        'order'  => '排序字段错误',
        'page' => '当前页为大于0的整数',
        'listRows' => '每页显示的条数范围为1-50',
    ];

    //上面必须包含以下字段，否则无效
    protected $scene = [
        /*亚数编辑商品时的验证*/
        'editGoods' => ['id'=> ['require','integer','gt'=>0],'user_id'=> ['require','integer','gt'=>0],'app_id'=> ['require','integer','gt'=>0],'cate_id','title','product_code','imgs_urls','imgs_ids','desc','price','goods_attrs','number','origin_number','pay_method','delivery_type','province','city','county','order'],
        /*艺货编辑商品时的验证*/
        'yihuoEditGoods' => ['id'=> ['require','integer','gt'=>0],'user_id'=> ['require','integer','gt'=>0],'app_id'=> ['require','integer','gt'=>0],'goods_belonger_name','cate_id','title','imgs_urls','imgs_ids','desc','price','goods_attrs','number','origin_number','pay_method','delivery_type','province','city','county','order','pick_up_time','start_delivery_time','end_delivery_time'],
        /*商品orther_info字段内容的验证*/
        'checkOrtherInfo' => ['user_name'=> ['require','min'=>'2'],'user_phone'=>['require','regex'=>'/^1[3|4|5|7|8]\d{9}$/']],
        /*商品属性goods_attrs字段内容的验证*/
        'checkAttr' => [
            /*'pattern'=> ['require','min'=>1],
            'standard'=>['require','min'=>1],*/
            'change_price' => ['require', 'integer'],
            'change_currency_price' => ['require', 'number'],
        ],
        /*卖家操作单个商品时的验证*/
        'sellerOperaGoods' => [
            'id',
            'user_id' => ['require','integer','gt'=>0],
        ],
        /*管理员操作单个商品时的验证*/
        'manageOperaGoods' => ['id','app_id'],
        /*管理员批量操作商品时的验证*/
        'manageBatchOperaGoods' => [
            'id'  => ['require','array','min'=>1],
            'app_id'
        ],
        /*管理员批量审核商品*/
        'manageBatchAuditGoods' => [
            'id'  => ['require','array','min'=>1],
            'status' => ['require','in'=>'1,2'],
            'app_id'
        ],
        /*管理员批量下架商品*/
        'manageBatchSoldOutGoods' => [
            'id'  => ['require','array','min'=>1],
            'app_id'
        ],
        /*卖家获取商品列表时的验证*/
        'getGoodsList' => [
            'user_id' => ['integer','gt'=>0],
            'status' => ['require','in'=>'-1,0,1,2,3,4'],
            'cate_id' => ['integer','egt'=>0],
            'price_start' => ['integer','egt'=>0],
            'price_end' => ['integer','egt'=>0],
            'page' => ['integer','gt'=>0],
            'listRows' => ['integer','gt'=>0],
            'recommend',
            'app_id','symbol'
        ],
        /*管理员推荐某个商品*/
        'recommend' => ['id', 'recommend', 'app_id'],
        'myGoodsDetail' => ['id','user_id'],
        'getRecommendList' => ['app_id', 'limit', 'recommend', 'is_sell'],
    ];


}